package com.wrh.demo.config;

import com.wrh.demo.SpringBootDemoApplication;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ClassUtils;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@Slf4j
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        String basePackage = ClassUtils.getPackageName(SpringBootDemoApplication.class);
        log.debug("swagger文档扫描包：{}", basePackage);
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                // 需要扫描的包，视项目情况修改
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("接口说明文档")
                .contact(new Contact("hxlc", "http://www.hxgis.com", null))
                .version("1.0")
                .build();
    }
}
